<template>
  <view class="content" style="background: #f5f6f6;">
    <!-- #ifdef APP-PLUS -->
    <view class="status_bar">
      <view class="top_view"></view>
    </view>
    <!-- #endif -->

    <view class="account">
      <view class="account_header">
        <view class="header_cumulative clear">
          <text class="fl">累计赚取({{CODECONFIG.signBaseCode}})</text>
          <text class="fr" @click="goPage('profitList/profitList')">明细</text>
        </view>
        <view class="header_money">
          <text class="money">{{userInfos.allProfit}}</text>
          <text class="coin">{{CODECONFIG.signBaseCode}}</text>
        </view>
        <view class="header_investment clear">
          <text class="fl">累计投入：{{userInfos.allInvest}} {{CODECONFIG.signBaseCode}}</text>
          <text class="fr">成功打卡：{{userInfos.signUpDays}} 天</text>
        </view>
        <view class="header_Invitation">
          <button @click="getInvit()">领取邀请奖励</button>
        </view>
      </view>
      <view class="account_list">
        <view class="item clear item_date">
          <view class="fl">
            <!-- <text style="font-size: 40rpx;">{{$formta((new Date().setDate(new Date().getDate()-1) ),'dd日')}}</text> -->
            <text style="font-size: 40rpx;">{{$formta(new Date(),'dd日')}}</text>
            <text style="font-size: 22rpx;">{{$formta(new Date(),'MM/yyyy')}}</text>
          </view>
          <text class="fr" v-if="signInFlag == 'NO' && userFlag == 'NO'">未参与</text>
          <text class="fr" v-else-if="userFlag == 'YES' && (dayPrize <= 0)">待分配</text>
          <text class="fr" v-else-if="userPrize == 'YES'" style="color: #fd5454;">+{{dayPrize}}</text>
          <text class="fr" v-else-if="signInFlag == 'YES'">待打卡</text>
          <!-- <text>{{signInFlag}},{{userPrize}},{{userFlag}}</text> -->
        </view>
      </view>
      <view class="account_list">
        <!-- <view class="item clear">
          <text class="fl" @click="goPage('../invitation/invitation')">邀请好友一起打卡</text>
          <view class="fr"><uni-icon type="arrowright" color="#585858" size="20"></uni-icon></view>
        </view> -->
        <view class="item clear" @click="goPage('myInvitation/myInvitation')">
          <text class="fl">邀请记录</text>
          <view class="fr">
            <uni-icon type="arrowright" color="#585858" size="20"></uni-icon>
          </view>
        </view>
      </view>
    </view>
    <HMmessages ref="HMmessages" @complete="HMmessages = $refs.HMmessages" @clickMessage="clickMessage"></HMmessages>
  </view>
</template>

<script>
  import {
    uniIcon
  } from '@dcloudio/uni-ui';
  import service from './service.js';
  import HMmessages from '@/components/HM-messages/HM-messages.vue';
  import { mapGetters } from 'vuex'
  export default {
    components: {
      uniIcon,
      HMmessages
    },
    computed: {
      ...mapGetters(['CODECONFIG'])
    },
    data() {
      return {
        userInfos: {
          allInvest: 0,
          allProfit: 0,
          signUpDays: 0
        },
        userPrize: 'NO',
        userFlag: 'NO',
        signInFlag: 'NO',
        dayPrize: 0,
      };
    },
    onShow() {
      this.getAllprofit();
      this.profitFlag();
      this.SignFlag();
      this.getSignDay();
      this.getCurrentProfit();
    },
    methods: {
      //领取邀请红包
      getInvit() {
        service.getInvit().then(({
          data
        }) => {
          if (data.code == '100200') {
            this.HMmessages.show('领取成功', {
              textAlign: 'center',
              background: '#356e36',
              fontColor: '#fff'
            });
            this.getAllprofit();
          } else {
            this.errors(data.msg);
          }
        })
      },
      //查询今日红包
      getCurrentProfit() {
        service.getCurrentProfit().then(({
          data
        }) => {
          if (data.code == '100200') {
            this.dayPrize = data.data && data.data.allotProfit ? data.data.allotProfit : 0;
          } else {
            this.errors(data.msg);
          }
        });
      },
      //领红包标记
      profitFlag() {
        service.profitFlag().then(({
          data
        }) => {
          if (data.code == '100200') {
            this.userPrize = data.data.profit;
          } else {
            this.errors(data.msg);
          }
        })
      },
      //打卡标记
      SignFlag() {
        service.SignFlag().then(({
          data
        }) => {
          if (data.code == '100200') {
            this.userFlag = data.data.signup;
          } else {
            this.errors(data.msg);
          }
        })
      },
      //报名标记
      getSignDay() {
        service.SignDay().then(({
          data
        }) => {
          if (data.code == '100200') {
            this.signInFlag = data.data.signin;
          } else {
            this.errors(data.msg);
          }
        });
      },
      //获取总收益
      getAllprofit() {
        this.$api.showLoading();
        service.getAllprofit().then(({
          data
        }) => {
          this.$api.hideLoading()
          if (data.code == '100200') {
            this.userInfos = Object.assign({}, data.data)
          } else {
            this.errors(data.msg);
          }
        });
      },
      //前往页面
      goPage(url) {
        uni.navigateTo({
          url: url
        });
      },
      //错误提示
      errors(text) {
        this.HMmessages.show(text, {
          textAlign: 'center',
          background: '#74272d',
          fontColor: '#fff'
        });
      }
    }
  };
</script>

<style lang="scss">
  @import './style.scss';
</style>
